package com.gitee.openviducn.inspector.domain.vo.response.openvidu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.gitee.openviducn.inspector.domain.vo.response.BaseResponse;
import io.openvidu.java.client.Publisher;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * @Author: https://gitee.com/wesleyOne
 * @Date: 03.03 2020
 */
@ApiModel(value = "Publisher信息")
@Getter
@Setter
public class PublisherVO extends BaseResponse {
    private static final long serialVersionUID = 5814677500992602802L;

    private String streamId;
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date createdAt;
    private Boolean hasVideo;
    private Boolean hasAudio;
    private Boolean audioActive;
    private Boolean videoActive;
    private Integer frameRate;
    private String typeOfVideo;
    private String videoDimensions;

    public static PublisherVO build(Publisher p) {
        PublisherVO vo = new PublisherVO();
        vo.setStreamId(p.getStreamId());
        vo.setCreatedAt(new Date(p.createdAt()));
        vo.setHasVideo(p.hasVideo());
        vo.setHasAudio(p.hasAudio());
        vo.setAudioActive(p.isAudioActive());
        vo.setVideoActive(p.isVideoActive());
        vo.setFrameRate(p.getFrameRate());
        vo.setTypeOfVideo(p.getTypeOfVideo());
        vo.setVideoDimensions(p.getVideoDimensions());
        return vo;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
